using UnityEngine;

public class PoliceLights : MonoBehaviour
{
	public static PoliceLights instance;

	public GameObject[] lights;

	public int lights_frame_length = 25;

	[HideInInspector]
	public bool lights_active;

	private int light_counter;

	private int counter;

	private AudioSource siren_sound;

	private void Start()
	{
		instance = this;
		siren_sound = GetComponent<AudioSource>();
		StopLights();
	}

	public static PoliceLights GetInstance()
	{
		return instance;
	}

	private void Update()
	{
		Lighten();
	}

	private void StopLights()
	{
		siren_sound.Stop();
		if (lights.Length > 0)
		{
			GameObject[] array = lights;
			foreach (GameObject gameObject in array)
			{
				gameObject.SetActive(value: false);
			}
		}
	}

	private void SwitchLight()
	{
		if (light_counter >= lights.Length)
		{
			light_counter = 0;
		}
		int num = 0;
		GameObject[] array = lights;
		foreach (GameObject gameObject in array)
		{
			if (light_counter == num)
			{
				gameObject.SetActive(value: true);
			}
			else
			{
				gameObject.SetActive(value: false);
			}
			num++;
		}
	}

	private void Lighten()
	{
		if (lights_active)
		{
			counter++;
			if (counter > lights_frame_length)
			{
				light_counter++;
				SwitchLight();
				counter = 0;
			}
		}
	}

	public void SwitchLightState()
	{
		if (lights_active)
		{
			lights_active = false;
			siren_sound.Stop();
			StopLights();
		}
		else
		{
			lights_active = true;
			siren_sound.Play();
		}
	}
}
